package com.hub.realtime.resource;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hub.realtime.resource.dto.input.FlinkVersionQueryParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hub.realtime.common.annotation.Log;
import com.hub.realtime.common.core.controller.BaseController;
import com.hub.realtime.common.core.domain.AjaxResult;
import com.hub.realtime.common.enums.BusinessType;
import com.hub.realtime.resource.domain.ResFlinkVersions;
import com.hub.realtime.resource.service.IResFlinkVersionsService;
import com.hub.realtime.common.utils.poi.ExcelUtil;
import com.hub.realtime.common.core.page.TableDataInfo;

/**
 * Flink版本信息Controller
 *
 * @author wupeng
 * @date 2022-01-07
 */
@RestController
@RequestMapping("/resource/flinkversions")
public class ResFlinkVersionsController extends BaseController {
    @Autowired
    private IResFlinkVersionsService resFlinkVersionsService;

    /**
     * 查询Flink版本信息列表
     */
    @PreAuthorize("@ss.hasPermi('resource:flinkversions:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlinkVersionQueryParam param) {
        Page<ResFlinkVersions> page = resFlinkVersionsService.list(param);
        return getDataTable(page.getRecords(),page.getTotal());
    }

    @GetMapping("/allList")
    public TableDataInfo allList() {
        List<ResFlinkVersions> list = resFlinkVersionsService.allList();
        return getDataTable(list,null);
    }

    /**
     * 导出Flink版本信息列表
     */
    @PreAuthorize("@ss.hasPermi('resource:flinkversions:export')")
    @Log(title = "Flink版本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlinkVersionQueryParam param) {
        List<ResFlinkVersions> list = resFlinkVersionsService.list(param).getRecords();
        ExcelUtil<ResFlinkVersions> util = new ExcelUtil<ResFlinkVersions>(ResFlinkVersions.class);
        util.exportExcel(response, list, "Flink版本信息数据");
    }

    /**
     * 获取Flink版本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:flinkversions:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(resFlinkVersionsService.getBaseMapper().selectById(id));
    }

    /**
     * 新增Flink版本信息
     */
    @PreAuthorize("@ss.hasPermi('resource:flinkversions:add')")
    @Log(title = "Flink版本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResFlinkVersions resFlinkVersions) {
        return toAjax(resFlinkVersionsService.saveInfo(resFlinkVersions));
    }

    /**
     * 修改Flink版本信息
     */
    @PreAuthorize("@ss.hasPermi('resource:flinkversions:edit')")
    @Log(title = "Flink版本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResFlinkVersions resFlinkVersions) {
        return toAjax(resFlinkVersionsService.saveInfo(resFlinkVersions));
    }

    /**
     * 删除Flink版本信息
     */
    @PreAuthorize("@ss.hasPermi('resource:flinkversions:remove')")
    @Log(title = "Flink版本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(resFlinkVersionsService.deleteInfos(ids));
    }
}
